#!/bin/bash

flink=/opt/module/flink-1.13.6/bin/flink
jar=/opt/module/flink-1.13.6/realtime-projject-1.0-SNAPSHOT.jar
apps=(
com.atguigu.yx.app.App_02_DimApp.DimApp
com.atguigu.yx.app.App_03_DwdApp.Dwd_00_Dwd_splitFlow_App.Dwd_00_Dwd_splitFlow_App
com.atguigu.yx.app.App_03_DwdApp.Dwd_01_UV_App.Dwd_01_Dwd_UVDetail_App
)

running_apps=`$flink list 2>/dev/null | awk  '/RUNNING/ {print \$(NF-1)}'`

for app in ${apps[*]} ; do
    app_name=`echo $app | awk -F. '{print \$NF}'`

    if [[ "${running_apps[@]}" =~ "$app_name" ]]; then
        echo ""
        echo "-----------------------------------"
        echo "$app_name 已经启动,无序重复启动...."
        echo "-----------------------------------"
        echo ""
    else
         echo ""
         echo "-----------------------------------"
         echo "启动应用: $app_name"
        $flink run -d -c $app $jar
        echo "-----------------------------------"
        echo ""

    fi
done